﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMS_Master.DTO.Personnel;
using TMS_Master.Personnel_module;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace TMS_Master
{
    public class TMSAppService :  CrudAppService
        <Become,
        BecomeDTO,
        Guid,
        PagedAndSortedResultRequestDto,
        BecomeDTOText>,
        ITMSAppService 
    {
        public readonly IRepository<Become, Guid> tMSApp;
        public TMSAppService(IRepository<Become, Guid> _tMSApp)  : base(_tMSApp)
        {
            tMSApp = _tMSApp;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="Become"></param>
        /// <returns></returns>
        public async Task<int> AddBecome(BecomeDTO Become)
        {
            Become Add = ObjectMapper.Map<BecomeDTO, Become>(Become);
            await tMSApp.InsertAsync(Add);
            return 1;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task DelBecome(Guid Id)
        {
            await tMSApp.DeleteAsync(Id);
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task<BecomeDTO> FanBecome(Guid Id)
        {
            Become b = await tMSApp.GetAsync(Id);
            BecomeDTO fan = ObjectMapper.Map<Become, BecomeDTO>(b);
            return fan;
        }
        
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public async Task<List<BecomeDTO>> GetBecome()
        {
            List<Become> p = await tMSApp.ToListAsync();
            List<Become> becomes = p;
            List<BecomeDTO> becomeDTOs = ObjectMapper.Map<List<Become>, List<BecomeDTO>>(becomes);
            return becomeDTOs;

        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="become"></param>
        /// <returns></returns>
        public async Task<int> UptBecome(BecomeDTO become)
        {
            Become e = await tMSApp.GetAsync(become.Id);
            e.BecomeName = become.BecomeName;
            return 1;
        }
    }
  
}
